<!-- Added to prevent iFrame exploit. Need to comment out for portlet to work -->
<script type="text/javascript">
    if (top.location!= self.location) {
        top.location = self.location.href
    }
</script>
<!-- end of comment out line -->

<!-- common to all login jsps - not localized information -->
<%
/*
 * @(#)login_common.jsp
 *
 * Copyright (c) 2001-2011 BMC Software, Inc.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * BMC Software, Inc ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement between
 * you and BMC Software, Inc.
 */
%>
<%@ page import="com.remedy.arsys.share.MessageTranslation" %>
<%@ page import="com.remedy.arsys.config.Configuration" %>
<%@ page import="com.remedy.arsys.stubs.SessionData" %>
<%@ page import="com.remedy.arsys.session.HttpSessionKeys" %>
<%@ page import="com.remedy.arsys.session.Params" %>
<%@ page import="com.remedy.arsys.stubs.ARServerUserBean" %>
<%@ page import="com.remedy.arsys.share.CacheDirectiveController" %>
<%@ page import="com.remedy.arsys.support.Validator" %>
<%@ page import="java.util.regex.Pattern"%>
<jsp:useBean id="userbean" class="com.remedy.arsys.stubs.ARServerUserBean" scope="request">
</jsp:useBean>
<%
   // initialize data
   String msg = (String)session.getAttribute(HttpSessionKeys.LOGIN_MSG);
   if (msg == null)
       msg = "";
   else
       msg = msg.replace('\n', ' ').replace('\r', ' ');

   String ipOverrideMsg = (String)session.getAttribute(HttpSessionKeys.MULTI_IP_OVERRIDE_MSG);
   if (ipOverrideMsg == null)
      ipOverrideMsg = "";

   String name = (String)session.getAttribute(HttpSessionKeys.LOGIN_NAME);
   if (name == null)
       name = "";

   String locale = SessionData.getLocale(request);

   String nextPage = (String)request.getParameter(Params.GOTO_URL);
   if (nextPage == null)
       nextPage = "";

   String server = (String)request.getParameter(Params.SERVER);
   if (server == null)
       server = "";

   boolean usererror = false;
   if (session.getAttribute(HttpSessionKeys.LOGIN_USER_ERROR) != null)
      usererror = true;

   boolean passworderror = false;
   if (session.getAttribute(HttpSessionKeys.PASSWORD_ERROR) != null)
      passworderror = true;

   String login_img = "images/login_image.jpg";
   String logo_img = "images/login_logo.gif";
   String iframeurl = null;
   String requrl = (String)session.getAttribute(HttpSessionKeys.TARGET_URL);
   if (requrl == null)
	   requrl = Validator.StripOffScriptTag(request.getQueryString());
   else
	   requrl = Validator.StripOffScriptTag(requrl);
   if(requrl!=null)
		requrl=requrl.replaceAll(Pattern.quote("\""), "%22"); 
   if (requrl != null && (requrl.length()>0) && requrl.charAt(0) == '/') {
       int appidx = requrl.indexOf("/apps/");
       if (appidx != -1) {
       	   // a block of code moved to ARServerUserBean.java to work around the issue in weblogic
       	   iframeurl = userbean.calculateIframeURLForLogin(request, requrl, session, locale);
       }
   }
   
   String shortVersion = Configuration.getInstance().getShortClientVersion();
   String titleStr     = "BMC&nbsp;Remedy&nbsp;Mid&nbsp;Tier&nbsp;" + shortVersion;
  //need CacheDirectiveController to force content update whenever forwarding (see method doc)
   CacheDirectiveController.forceContentUpdate(request, response);
%>


<script type="text/javascript" src="<%=request.getContextPath()+Login.JS_RESOURCES+"bootstrap.js"%>"></script>

<script language="JavaScript">

/* function to initialize error messages,
 * edit fields
 * if this was reached via a back button,
 * don't show previous error messages
 * this confuses the user
 */
function setInitialFormState() {
    var usererror = false;
    var passworderror = false;
    if (this.document.loginForm.initialState.value == "-1") {
        this.document.loginForm.initialState.value = "0";
        var ipmsg = "<%=ipOverrideMsg%>";
        if (ipmsg.length > 5) {
            var reply = window.confirm(ipmsg + " <%= MessageTranslation.getLocalizedText(locale, "Do you wish to override?")%>");
            if (reply)
                location.href = location.href + "?ipoverride=1";
        } else {
            if (msg.length > 5) {
                var re = new RegExp("<br>|<b>|<\/b>", "g");
               
                alert(msg.replace(re, ''));
                var domObj = this.document.getElementById("LoginMsg-id");
                domObj.innerHTML = msg;
            }
            usererror = <%=usererror%>;
            passworderror = <%=passworderror%>;
        }
    } else {
        // this isn't the first time this form has been displayed
        // show a clean form, get rid of any errors that might have been shown
        var domObj = this.document.getElementById("LoginMsg-id");
        domObj.innerHTML = "";

    }
    // change look of labels to show error?
    domObj = this.document.getElementById("LoginLabel-id");
    domObj.className = usererror ? "LoginError" : "Login";
    domObj = this.document.getElementById("PasswordLabel-id");
    domObj.className = passworderror ? "LoginError" : "Login";
}
function getCookieValue(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = -1;
    if (dc.indexOf(prefix) == 0) {
        begin = 0;
    } else {
        begin = dc.indexOf("; " + prefix);
        if (begin != -1) begin += 2;
    }
    if (begin == -1) {
        return null;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    end = dc.length;

    var cookievalue = dc.substring(begin + prefix.length, end);
    return decodeURIComponent(cookievalue);
}

function detectPopupBlockers() {
	// get the path
	var pathstr = requrl;
	var patharr = pathstr.split("/");
	pathstr = patharr[0];
	
	var popBlock = getCookieValue('P');
	if (popBlock != 1) {
		popBlock = 1; //run popup check exactly once
		try {
			var top = 0;
			var left = screen.width;
			//use 'about:blank' so no need to go back to midtier
			var testWin = window.open('about:blank','PopupTest','width=1,height=1,left=' + left + ',top=' + top + ',scrollbars=no,toolbar=no,menubars=no,location=no,status=no,titlebar=no');
			var testWinName = testWin.name;
			testWin.close();
		} catch (exception) {
			window.focus();
			addAlert("<%=MessageTranslation.getLocalizedText(locale, "Popup blockers must be disabled to use this application.")%>");
		}
		//set a cookie to show you have already displayed a message
		// Amethyst-209: Use shorter cookie name "P" instead of "PopBlock"
		var popupCookie = "P=" + popBlock + ";path=/" + pathstr;
		document.cookie = popupCookie;
	}
}

function shoeIE8VersionAlert() {
	// get the path
	var pathstr = requrl;
	var patharr = pathstr.split("/");
	pathstr = patharr[0];
	
	var ie8Warn = getCookieValue('I');
	if (ie8Warn != 1) {
		ie8Warn = 1; //run popup check exactly once
		addAlert("<%=MessageTranslation.getLocalizedText(locale, "For Midtier to work properly on Internet Explorer 8, Please make sure that you have required patch installed. Please see")%>" + " <a target='_blank' href='http://www.microsoft.com/technet/security/bulletin/MS10-018.mspx'>Microsoft Security Bulletin MS10-018</a>");
		//set a cookie to show you have already displayed a message
		var ie8Cookie = "I=" + ie8Warn + ";path=/" + pathstr;
		document.cookie = ie8Cookie;
	}
}


function addAlert(msg) {
	//document.getElementById("alertArea").style.display = "block";
	//var prnt = document.getElementById("errList");
	//var li = document.createElement("LI");
	//var para = document.createElement('P');
	//para.className = "warning";
	//para.innerHTML = msg;
	//li.appendChild(para);
	//prnt.appendChild(li);
}


/*
 * This function performs the necessary initialization
 * when page is loaded.
 */
function initLogin() {
    // check if cookie is enabled so applications can run
    if (document.cookie == "") {
        alert("<%=MessageTranslation.getLocalizedText(locale, "Cookies are disabled. Cannot access mid-tier with this setting.\\nPlease configure your browser to accept cookies.")%>");
        return;
    }

	detectPopupBlockers();
	
	detectFlash();
	
    setInitialFormState();

    // Check browser type and version
    var browserOK = false;
    var browserApp = navigator.appName;

    // Netscape
    if (browserApp == "Netscape") {
        //all NN7 browsers and above are Gecko based
        if (navigator.userAgent.indexOf("Gecko") != -1)
            browserOK = true;
    }
    // IE
    else if (browserApp == "Microsoft Internet Explorer") {
        var browserVersion = navigator.appVersion;
        var MSIEindex = browserVersion.indexOf('MSIE ');

        // Check for IE version 6.0 or higher
        if (MSIEindex >= 0) {
            var MSIEversion = browserVersion.substring(MSIEindex+5);
            var vf = parseFloat(MSIEversion);
            if (vf >= 6.0)
                browserOK = true;
            if(vf == 8)
            	shoeIE8VersionAlert();
        }
    }

    // Generate message if needed
    if (!browserOK) {
        if ("<%=Configuration.getInstance().getProperty("arsystem.browser_version_error")%>" != "Off") {
            addAlert("<%=MessageTranslation.getLocalizedText(locale, "You appear to be running a browser that is not supported by the AR System. Please refer to the AR System compatibility matrix for information about which browsers are supported.")%>");
        }
    }

    // Clear login user name if it has not been set
    if (this.document.loginForm.username.value == "null")
        this.document.loginForm.username.value = "";

    this.document.loginForm.username.onkeypress = doSubmit;
    this.document.loginForm.pwd.onkeypress = doSubmit;
    this.document.loginForm.auth.onkeypress = doSubmit;
    
    if (requrl == null)
	   requrl = "";
   	this.document.loginForm.<%=HttpSessionKeys.TARGET_URL%>.value=requrl;
   
    setInitialFocus();
    setTimeout("loadJS()",1);

<% if(!Configuration.isBirtInit) { %>    
    runSampleReport();
<% } %>

}

function setInitialFocus() {
    // set focus to user input field
    document.loginForm.username.focus();
    document.loginForm.username.select();
}

function loadJS() {
    var head = document.getElementsByTagName('head')[0];
    var link= document.createElement('script'); 
    link.setAttribute("type", "text/plain");
    link.setAttribute("src","<%=request.getContextPath()+Login.JS_RESOURCES%>"+ARMTGetBrowserTypeString()+"/ClientCore.js");
    head.appendChild(link);

	//this is a dummy download of swf
	var url = "<%=request.getContextPath()%>"+"/resources/swf/background.swf";
	var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	if (isIE) {    
		var obj = document.createElement('object');
		document.body.appendChild(obj);
		obj.className="bkgImg";
		obj.classid= "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
		obj.id="bkgFlashImg";
		obj.movie = url;
		obj.wmode = "transparent";
		obj.style.height = "1px";
        obj.style.width = "1px";
        obj.style.position = "absolute";
        obj.style.top =0;
        obj.style.left = 0;
		
	}
	else
	{
		 var obj = document.createElement('embed');
         obj.setAttribute("src", url);
         obj.setAttribute("quality", "high");
         obj.className="bkgImg";
         obj.setAttribute("name", "bkgFlashImg");
         obj.setAttribute("type", "application/x-shockwave-flash");
         obj.setAttribute("wmode", "transparent");
         obj.style.height = "1px";
            obj.style.width = "1px";
            obj.style.position = "absolute";
            obj.style.top =0;
            obj.style.left = 0;      
         document.body.appendChild(obj);
	}
}

/*
 * This function handles the "Clear" button on page.
 */
function clearLogin() {
    // clear all input fields
    this.document.loginForm.username.value="";
    this.document.loginForm.pwd.value="";
    this.document.loginForm.auth.value="";

    this.document.loginForm.username.focus();
}

// Scrambles passwords using simple cipher algorithm
function getScrambledPassword(pwd) {
    var cipher = ['k', 's', 'z', 'h', 'x', 'b', 'p', 'j', 'v', 'c', 'g', 'f', 'q', 'n', 't', 'm'];
    var result="";
    if (pwd == null)
        pwd = "";
    pwd = encodeURIComponent(pwd);
    //alert("encoded password: " + pwd);
    for(var i=0;i<pwd.length;i++) {
            var cc = pwd.charCodeAt(i);
        result += cipher[Math.floor(cc/16)] + cipher[cc%16];
    }
    //alert("scrambled password: " + result);
    return result;
}

/*
 * This function validates the information on form
 * and then submits the action if data is correct.
 */
function doLogin() {
    // make sure user has entered a name
    if (this.document.loginForm.username.value == "") {
        alert("<%=MessageTranslation.getLocalizedText(locale, "You must enter a user name.")%>");
        return;
    }

    // get time zone from the system
    this.document.loginForm.timezone.value=getTimezone();

    // scramble the password before submitting
    this.document.loginForm.pwd.value = getScrambledPassword(this.document.loginForm.pwd.value);

    // submit the form action
    document.loginForm.submit();
}

/*
 * This function detects users key presses and sumbits the form
 * if the return key is hit.
 */
function doSubmit(evt) {
    var keycode;

    // extract key code from event
    if (navigator.appName.indexOf("Netscape") != -1)
        keycode = evt.which;
    else if (navigator.appName.indexOf("Microsoft") != -1)
        keycode = window.event.keyCode;

    // detect the "Return" key
    if (keycode == 13) {
        doLogin();

        if (navigator.appName.indexOf("Microsoft") != -1)
            // stop System Default Beep Sound.
            window.event.keyCode = 0;
    }
}

var msg = "<%=msg%>";
var requrl = "<%=requrl%>";
// var usererror = "<%=usererror%>";
// var passworderror = "<%=passworderror%>";

// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		try {
			// version will be set for 7.X or greater players
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
			flashVer = axo.GetVariable("$version");
		} catch (e) {
			try {
				// version will be set for 6.X players only
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				
				// installed player is some revision of 6.0
				// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
				// so we have to be careful. 
				
				// default to the first public version
				flashVer = "WIN 6,0,21,0";

				// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
				axo.AllowScriptAccess = "always";

				// safe to call for 6.0r47 or greater
				flashVer = axo.GetVariable("$version");
			} catch (e) {
				try {
					// version will be set for 4.X or 5.X player
					var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
					flashVer = axo.GetVariable("$version");
				} catch (e) {
					try {
						// version will be set for 3.X player
						var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
						flashVer = "WIN 3,0,18,0";
					} catch (e) {
						try {
							// version will be set for 2.X player
							var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
							flashVer = "WIN 2,0,0,11";
						} catch (e) {}
					}
				}
			}
		}
	}
	return flashVer;
}

//returns -1 : no flash player, 0 - older flash version, 1 - required version
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision){
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return -1;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

		// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return 1;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return 1;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return 1;
			}
		}
		return 0;
	}
}

function detectFlash() {
	if ("<%=Configuration.getInstance().getProperty("arsystem.flash.detect_flashplayer")%>" != "true") {
		return;
	}
	// Version check based upon the values defined in globals
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	if( hasRequestedVersion == -1 ) {
		addAlert("<%=MessageTranslation.getLocalizedText(locale, "Flash player is not detected.")%>" + "\n" +
				" <%=MessageTranslation.getLocalizedText(locale, "Download and install flash player from")%>" + "\n" +
				" <a target='_blank' href='http://www.adobe.com/go/getflashplayer'>http://www.adobe.com/go/getflashplayer</a>");
	}
	else if( hasRequestedVersion == 0) {
		addAlert("<%=MessageTranslation.getLocalizedText(locale, "Please upgrade your Flash Player to the minimum version")%>" + 
				" " + requiredMajorVersion + "." + requiredMinorVersion + "." + requiredRevision + "\n" +
				" <%=MessageTranslation.getLocalizedText(locale, "Download and install flash player from")%>" + "\n" +
				" <a target='_blank' href='http://www.adobe.com/go/getflashplayer'>http://www.adobe.com/go/getflashplayer</a>");
	}
}

var fetcher;
function runSampleReport(){
   if(!fetcher){
   		setFetcher();
   }   
   fetcher.onreadystatechange = processRequest;   
   var url = "<%=request.getContextPath()%>" +"/servlet/BirtReportServlet?pl";
   fetcher.open("GET", url, true);
   fetcher.send(null);
}

function processRequest() {
   if (fetcher.readyState == 4) {
      if (fetcher.status == 200) {
    	  <% Configuration.isBirtInit = true; %>
      }
      }

}

function setFetcher(){
   try {
    		/*ie5, saf, moz*/
    		fetcher=new XMLHttpRequest();
    	} catch(e){
    		try {
    			fetcher=new ActiveXObject("Msxml2.XMLHTTP");
    		} catch(e){
    			try {
    				fetcher=new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch (e) {
    			}
    	 };
	};	
}

</script>
<script>
var noDstTzs = [
{ tz:"ACT", offset:34200000 },
{ tz:"Africa/Abidjan", offset:0 },
{ tz:"Africa/Addis_Ababa", offset:10800000 },
{ tz:"Africa/Algiers", offset:3600000 },
{ tz:"Africa/Blantyre", offset:7200000 },
{ tz:"America/Anguilla", offset:-14400000 },
{ tz:"America/Araguaina", offset:-10800000 },
{ tz:"America/Atikokan", offset:-18000000 },
{ tz:"America/Belize", offset:-21600000 },
{ tz:"America/Caracas", offset:-16200000 },
{ tz:"America/Dawson_Creek", offset:-25200000 },
{ tz:"America/Noronha", offset:-7200000 },
{ tz:"Antarctica/Casey", offset:28800000 },
{ tz:"Antarctica/Davis", offset:25200000 },
{ tz:"Antarctica/DumontDUrville", offset:36000000 },
{ tz:"Antarctica/Mawson", offset:21600000 },
{ tz:"Asia/Aqtau", offset:18000000 },
{ tz:"Asia/Calcutta", offset:19800000 },
{ tz:"Asia/Dubai", offset:14400000 },
{ tz:"Asia/Kabul", offset:16200000 },
{ tz:"Asia/Kathmandu", offset:20700000 },
{ tz:"Asia/Rangoon", offset:23400000 },
{ tz:"Asia/Riyadh87", offset:11224000 },
{ tz:"Asia/Tokyo", offset:32400000 },
{ tz:"Atlantic/Cape_Verde", offset:-3600000 },
{ tz:"Australia/Eucla", offset:31500000 },
{ tz:"Etc/GMT+10", offset:-36000000 },
{ tz:"Etc/GMT+11", offset:-39600000 },
{ tz:"Etc/GMT+12", offset:-43200000 },
{ tz:"Etc/GMT+8", offset:-28800000 },
{ tz:"Etc/GMT+9", offset:-32400000 },
{ tz:"Etc/GMT-11", offset:39600000 },
{ tz:"Etc/GMT-12", offset:43200000 },
{ tz:"Etc/GMT-13", offset:46800000 },
{ tz:"Etc/GMT-14", offset:50400000 },
{ tz:"Pacific/Marquesas", offset:-34200000 },
{ tz:"Pacific/Norfolk", offset:41400000 }
];

var dstTzs = [
{ tz:"AET", offset:36000000, start:1223136000, end:1207411200 },
{ tz:"AGT", offset:-10800000, start:1223179200, end:1205632800 },
{ tz:"ART", offset:7200000, start:1209074400, end:1219957200 },
{ tz:"AST", offset:-32400000, start:1205064000, end:1225620000 },
{ tz:"Africa/Ceuta", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Africa/Tunis", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Africa/Windhoek", offset:3600000, start:1220752800, end:1207440000 },
{ tz:"America/Adak", offset:-36000000, start:1205067600, end:1225623600 },
{ tz:"America/Argentina/Cordoba", offset:-10800000, start:1223179200, end:1205632800 },
{ tz:"America/Argentina/San_Luis", offset:-14400000, start:0, end:0 },
{ tz:"America/Argentina/Tucuman", offset:-10800000, start:1223179200, end:1205632800 },
{ tz:"America/Asuncion", offset:-14400000, start:1224392400, end:1205031600 },
{ tz:"America/Boise", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"America/Cambridge_Bay", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"America/Campo_Grande", offset:-14400000, start:1223787600, end:1203217200 },
{ tz:"America/Cancun", offset:-21600000, start:1207472400, end:1225004400 },
{ tz:"America/Chicago", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Chihuahua", offset:-25200000, start:1207476000, end:1225008000 },
{ tz:"America/Cuiaba", offset:-14400000, start:1223787600, end:1203217200 },
{ tz:"America/Dawson", offset:-28800000, start:1205060400, end:1225616400 },
{ tz:"America/Denver", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"America/Detroit", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Edmonton", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"America/Ensenada", offset:-28800000, start:1207479600, end:1225011600 },
{ tz:"America/Fort_Wayne", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Glace_Bay", offset:-14400000, start:1205046000, end:1225602000 },
{ tz:"America/Godthab", offset:-10800000, start:1206838800, end:1224982800 },
{ tz:"America/Goose_Bay", offset:-14400000, start:1205038860, end:1225594860 },
{ tz:"America/Grand_Turk", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Halifax", offset:-14400000, start:1205046000, end:1225602000 },
{ tz:"America/Havana", offset:-18000000, start:1205038800, end:1224997200 },
{ tz:"America/Indiana/Knox", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Indiana/Marengo", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Indiana/Petersburg", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Indiana/Tell_City", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Indiana/Vevay", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Indiana/Vincennes", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Indiana/Winamac", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Inuvik", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"America/Iqaluit", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Juneau", offset:-32400000, start:1205064000, end:1225620000 },
{ tz:"America/Kentucky/Louisville", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Kentucky/Monticello", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Los_Angeles", offset:-28800000, start:1205060400, end:1225616400 },
{ tz:"America/Mazatlan", offset:-25200000, start:1207476000, end:1225008000 },
{ tz:"America/Menominee", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Merida", offset:-21600000, start:1207472400, end:1225004400 },
{ tz:"America/Mexico_City", offset:-21600000, start:1207472400, end:1225004400 },
{ tz:"America/Miquelon", offset:-10800000, start:1205042400, end:1225598400 },
{ tz:"America/Moncton", offset:-14400000, start:1205046000, end:1225602000 },
{ tz:"America/Monterrey", offset:-21600000, start:1207472400, end:1225004400 },
{ tz:"America/Montevideo", offset:-10800000, start:1223186400, end:1205035200 },
{ tz:"America/Montreal", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Nassau", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/New_York", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Nipigon", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Nome", offset:-32400000, start:1205064000, end:1225620000 },
{ tz:"America/North_Dakota/Center", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/North_Dakota/New_Salem", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Pangnirtung", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Rainy_River", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Rankin_Inlet", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Santiago", offset:-14400000, start:1223784000, end:1205031600 },
{ tz:"America/Sao_Paulo", offset:-10800000, start:1224385200, end:1234663200 },
{ tz:"America/Scoresbysund", offset:-3600000, start:1206838800, end:1224982800 },
{ tz:"America/St_Johns", offset:-12600000, start:1205037060, end:1225593060 },
{ tz:"America/Thule", offset:-14400000, start:1205046000, end:1225602000 },
{ tz:"America/Thunder_Bay", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Toronto", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"America/Vancouver", offset:-28800000, start:1205060400, end:1225616400 },
{ tz:"America/Whitehorse", offset:-28800000, start:1205060400, end:1225616400 },
{ tz:"America/Winnipeg", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"America/Yakutat", offset:-32400000, start:1205064000, end:1225620000 },
{ tz:"America/Yellowknife", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"Antarctica/McMurdo", offset:43200000, start:1222524000, end:1207404000 },
{ tz:"Antarctica/Palmer", offset:-14400000, start:1223784000, end:1205031600 },
{ tz:"Arctic/Longyearbyen", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Asia/Amman", offset:7200000, start:1206568800, end:1225404000 },
{ tz:"Asia/Anadyr", offset:43200000, start:1206799200, end:1224943200 },
{ tz:"Asia/Baku", offset:14400000, start:1206838800, end:1224979200 },
{ tz:"Asia/Beirut", offset:7200000, start:1206831600, end:1224968400 },
{ tz:"Asia/Damascus", offset:7200000, start:1206658800, end:1226005200 },
{ tz:"Asia/Gaza", offset:7200000, start:1207004400, end:1221087600 },
{ tz:"Asia/Irkutsk", offset:28800000, start:1206813600, end:1224957600 },
{ tz:"Asia/Istanbul", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Asia/Jerusalem", offset:7200000, start:1206666000, end:1221256800 },
{ tz:"Asia/Kamchatka", offset:43200000, start:1206799200, end:1224943200 },
{ tz:"Asia/Krasnoyarsk", offset:25200000, start:1206817200, end:1224961200 },
{ tz:"Asia/Magadan", offset:39600000, start:1206802800, end:1224946800 },
{ tz:"Asia/Nicosia", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Asia/Novosibirsk", offset:21600000, start:1206820800, end:1224964800 },
{ tz:"Asia/Omsk", offset:21600000, start:1206820800, end:1224964800 },
{ tz:"Asia/Sakhalin", offset:36000000, start:1206806400, end:1224950400 },
{ tz:"Asia/Tehran", offset:12600000, start:1206048600, end:1221939000 },
{ tz:"Asia/Vladivostok", offset:36000000, start:1206806400, end:1224950400 },
{ tz:"Asia/Yakutsk", offset:32400000, start:1206810000, end:1224954000 },
{ tz:"Asia/Yekaterinburg", offset:18000000, start:1206824400, end:1224968400 },
{ tz:"Asia/Yerevan", offset:14400000, start:1206828000, end:1224972000 },
{ tz:"Atlantic/Azores", offset:-3600000, start:1206838800, end:1224982800 },
{ tz:"Atlantic/Bermuda", offset:-14400000, start:1205046000, end:1225602000 },
{ tz:"Atlantic/Canary", offset:0, start:1206838800, end:1224982800 },
{ tz:"Atlantic/Faeroe", offset:0, start:1206838800, end:1224982800 },
{ tz:"Atlantic/Madeira", offset:0, start:1206838800, end:1224982800 },
{ tz:"Atlantic/Stanley", offset:-14400000, start:1220770800, end:1208667600 },
{ tz:"Australia/Adelaide", offset:34200000, start:1223137800, end:1207413000 },
{ tz:"Australia/Broken_Hill", offset:34200000, start:1223137800, end:1207413000 },
{ tz:"Australia/Currie", offset:36000000, start:1223136000, end:1207411200 },
{ tz:"Australia/Hobart", offset:36000000, start:1223136000, end:1207411200 },
{ tz:"Australia/LHI", offset:37800000, start:1223136000, end:1207407600 },
{ tz:"Australia/Melbourne", offset:36000000, start:1223136000, end:1207411200 },
{ tz:"Australia/Perth", offset:32400000, start:1224957600, end:1238263200 },
{ tz:"CET", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"CST6CDT", offset:-21600000, start:1205053200, end:1225609200 },
{ tz:"Chile/EasterIsland", offset:-21600000, start:1223784000, end:1205031600 },
{ tz:"ECT", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"EET", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"EST5EDT", offset:-18000000, start:1205049600, end:1225605600 },
{ tz:"Eire", offset:0, start:1206838800, end:1224982800 },
{ tz:"Europe/Amsterdam", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Andorra", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Athens", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Belfast", offset:0, start:1206838800, end:1224982800 },
{ tz:"Europe/Belgrade", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Berlin", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Bratislava", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Brussels", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Bucharest", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Budapest", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Chisinau", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Copenhagen", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Gibraltar", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Helsinki", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Kaliningrad", offset:7200000, start:1206835200, end:1224979200 },
{ tz:"Europe/Kiev", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Lisbon", offset:0, start:1206838800, end:1224982800 },
{ tz:"Europe/Luxembourg", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Madrid", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Malta", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Minsk", offset:7200000, start:1206835200, end:1224979200 },
{ tz:"Europe/Monaco", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Moscow", offset:10800000, start:1206831600, end:1224975600 },
{ tz:"Europe/Riga", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Rome", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Samara", offset:14400000, start:1206828000, end:1224972000 },
{ tz:"Europe/Simferopol", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Sofia", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Stockholm", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Tallinn", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Tirane", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Uzhgorod", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Vaduz", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Vienna", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Vilnius", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Volgograd", offset:10800000, start:1206831600, end:1224975600 },
{ tz:"Europe/Warsaw", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Europe/Zaporozhye", offset:7200000, start:1206838800, end:1224982800 },
{ tz:"Europe/Zurich", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"Indian/Mauritius", offset:14400000, start:0, end:0 },
{ tz:"MET", offset:3600000, start:1206838800, end:1224982800 },
{ tz:"MST7MDT", offset:-25200000, start:1205056800, end:1225612800 },
{ tz:"NST", offset:43200000, start:1222524000, end:1207404000 },
{ tz:"NZ-CHAT", offset:45900000, start:1222524000, end:1207404000 },
{ tz:"PST8PDT", offset:-28800000, start:1205060400, end:1225616400 },
{ tz:"WET", offset:0, start:1206838800, end:1224982800 }
];

var USTzs = [
{ tz:"AST", offset:-32400000 },
{ tz:"America/Adak", offset:-36000000 },
{ tz:"America/Anchorage", offset:-32400000 },
{ tz:"America/Atka", offset:-36000000 },
{ tz:"America/Boise", offset:-25200000 },
{ tz:"America/Chicago", offset:-21600000 },
{ tz:"America/Denver", offset:-25200000 },
{ tz:"America/Detroit", offset:-18000000 },
{ tz:"America/Fort_Wayne", offset:-18000000 },
{ tz:"America/Indiana/Indianapolis", offset:-18000000 },
{ tz:"America/Indiana/Knox", offset:-21600000 },
{ tz:"America/Indiana/Marengo", offset:-18000000 },
{ tz:"America/Indiana/Petersburg", offset:-18000000 },
{ tz:"America/Indiana/Tell_City", offset:-21600000 },
{ tz:"America/Indiana/Vevay", offset:-18000000 },
{ tz:"America/Indiana/Vincennes", offset:-18000000 },
{ tz:"America/Indiana/Winamac", offset:-18000000 },
{ tz:"America/Indianapolis", offset:-18000000 },
{ tz:"America/Juneau", offset:-32400000 },
{ tz:"America/Kentucky/Louisville", offset:-18000000 },
{ tz:"America/Kentucky/Monticello", offset:-18000000 },
{ tz:"America/Knox_IN", offset:-21600000 },
{ tz:"America/Los_Angeles", offset:-28800000 },
{ tz:"America/Louisville", offset:-18000000 },
{ tz:"America/Menominee", offset:-21600000 },
{ tz:"America/New_York", offset:-18000000 },
{ tz:"America/Nome", offset:-32400000 },
{ tz:"America/North_Dakota/Center", offset:-21600000 },
{ tz:"America/North_Dakota/New_Salem", offset:-21600000 },
{ tz:"America/Shiprock", offset:-25200000 },
{ tz:"America/Yakutat", offset:-32400000 },
{ tz:"CST", offset:-21600000 },
{ tz:"IET", offset:-18000000 },
{ tz:"Navajo", offset:-25200000 },
{ tz:"PST", offset:-28800000 },
{ tz:"SystemV/CST6CDT", offset:-21600000 },
{ tz:"SystemV/EST5EDT", offset:-18000000 },
{ tz:"SystemV/MST7MDT", offset:-25200000 },
{ tz:"SystemV/PST8PDT", offset:-28800000 },
{ tz:"SystemV/YST9YDT", offset:-32400000 },
{ tz:"US/Alaska", offset:-32400000 },
{ tz:"US/Aleutian", offset:-36000000 },
{ tz:"US/Central", offset:-21600000 },
{ tz:"US/East-Indiana", offset:-18000000 },
{ tz:"US/Eastern", offset:-18000000 },
{ tz:"US/Indiana-Starke", offset:-21600000 },
{ tz:"US/Michigan", offset:-18000000 },
{ tz:"US/Mountain", offset:-25200000 },
{ tz:"US/Pacific", offset:-28800000 },
{ tz:"US/Pacific-New", offset:-28800000 },
{ tz:"America/Cambridge_Bay", offset:-25200000 },
{ tz:"America/Dawson", offset:-28800000 },
{ tz:"America/Edmonton", offset:-25200000 },
{ tz:"America/Glace_Bay", offset:-14400000 },
{ tz:"America/Goose_Bay", offset:-14400000 },
{ tz:"America/Halifax", offset:-14400000 },
{ tz:"America/Inuvik", offset:-25200000 },
{ tz:"America/Iqaluit", offset:-18000000 },
{ tz:"America/Moncton", offset:-14400000 },
{ tz:"America/Montreal", offset:-18000000 },
{ tz:"America/Nipigon", offset:-18000000 },
{ tz:"America/Pangnirtung", offset:-18000000 },
{ tz:"America/Rainy_River", offset:-21600000 },
{ tz:"America/Rankin_Inlet", offset:-21600000 },
{ tz:"America/St_Johns", offset:-12600000 },
{ tz:"America/Thunder_Bay", offset:-18000000 },
{ tz:"America/Toronto", offset:-18000000 },
{ tz:"America/Vancouver", offset:-28800000 },
{ tz:"America/Whitehorse", offset:-28800000 },
{ tz:"America/Winnipeg", offset:-21600000 },
{ tz:"America/Yellowknife", offset:-25200000 },
{ tz:"CNT", offset:-12600000 },
{ tz:"Canada/Atlantic", offset:-14400000 },
{ tz:"Canada/Central", offset:-21600000 },
{ tz:"Canada/Eastern", offset:-18000000 },
{ tz:"Canada/Mountain", offset:-25200000 },
{ tz:"Canada/Newfoundland", offset:-12600000 },
{ tz:"Canada/Pacific", offset:-28800000 },
{ tz:"Canada/Yukon", offset:-28800000 },
{ tz:"SystemV/AST4ADT", offset:-14400000 }
];

function getTimezone() {
	var i, d1, d2, d3, d4, off1, off2, off3, off4;

	// first check for timezone with no daylight savings
	d1 = new Date(2004, 0, 1, 0, 0, 0, 0);
	off1 = d1.getTimezoneOffset() * 60000;
	d2 = new Date(2004, 3, 1, 0, 0, 0, 0);
	off2 = d2.getTimezoneOffset() * 60000;
	d3 = new Date(2004, 6, 1, 0, 0, 0, 0);
	off3 = d3.getTimezoneOffset() * 60000;
	d4 = new Date(2004, 9, 1, 0, 0, 0, 0);
	off4 = d4.getTimezoneOffset() * 60000;

	if (off1 == off2 && off2 == off3 && off3==off4 && off4==off1) {
		for (i=0; i<noDstTzs.length; i++) {
			if (noDstTzs[i].offset == -off1)
				return noDstTzs[i].tz;
		}
	}

	// now check for timezone with daylight savings
	for (i=0; i<dstTzs.length; i++) {
		if (dstTzs[i].start==-1||dstTzs[i].end==-1)
			continue;
		d1=new Date((dstTzs[i].start-1)*1000); //1 second before DST start
		d2=new Date((dstTzs[i].start+1)*1000); //1 second after DST start
		d3=new Date((dstTzs[i].end-1)*1000); //1 second before DST end
		d4=new Date((dstTzs[i].end+1)*1000); //1 second after DST end
		off1 = d1.getTimezoneOffset() * 60000;
		off2 = d2.getTimezoneOffset() * 60000
		off3 = d3.getTimezoneOffset() * 60000
		off4 = d4.getTimezoneOffset() * 60000
		if (dstTzs[i].tz.indexOf("Australia/Perth") != -1) {
			if ((off1!=off2) && (off3!=off4) && (-off3 == dstTzs[i].offset))
			return dstTzs[i].tz;
		}
		else if ((off1!=off2) && (off3!=off4) && (-off4 == dstTzs[i].offset))
			return dstTzs[i].tz;
	}
	// Nothing matches to windows bug relating to the changes in 2007 US DST rules.
	for (i=0; i<USTzs.length; i++) {
		d1=new Date(2007,12,1,1,0,0,0);
		off1 = d1.getTimezoneOffset() * 60000;
		if (-off1 == USTzs[i].offset)
			return USTzs[i].tz;
	}
	return "use_server";
}

</script>
